home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / beginn1a / form1.frm next >
Text File  |  1999-09-12  |  2KB  |  73 lines

  1. VERSION 5.00
  2. Begin VB.Form Form1 
  3.    Caption         =   "Form1"
  4.    ClientHeight    =   2640
  5.    ClientLeft      =   3555
  6.    ClientTop       =   2715
  7.    ClientWidth     =   4410
  8.    LinkTopic       =   "Form1"
  9.    ScaleHeight     =   176
  10.    ScaleMode       =   3  'Pixel
  11.    ScaleWidth      =   294
  12.    Begin VB.CommandButton Command1 
  13.       Caption         =   "Command1"
  14.       Height          =   375
  15.       Left            =   1320
  16.       TabIndex        =   0
  17.       Top             =   600
  18.       Width           =   1695
  19.    End
  20. End
  21. Attribute VB_Name = "Form1"
  22. Attribute VB_GlobalNameSpace = False
  23. Attribute VB_Creatable = False
  24. Attribute VB_PredeclaredId = True
  25. Attribute VB_Exposed = False
  26. Option Explicit
  27.  
  28. Private Sub Command1_Click()
  29.  
  30. 'Always start ALL routines by declaring the variables you will be using!
  31.     Dim the_secret_number As Long
  32.     Dim counter As Long
  33.     Dim users_guess_string As String
  34.     Dim users_guess_number As Long
  35.  
  36. 'First we'll randomize the timer so that we get a different
  37. 'random number every time we play.
  38.  
  39.     Randomize Timer
  40.  
  41. 'Next we'll generate our random number between 1 and 100
  42.  
  43.     the_secret_number = Int((100 * Rnd) + 1)
  44.  
  45. 'Now we'll set up a For-Next loop which will give the user 10 tries at
  46. 'guessing the secret number.
  47.  
  48. For counter = 1 To 10
  49.     
  50.     'Have the user take a guess.
  51.     users_guess_string = InputBox("Take a guess between 1 and 100")
  52.     'Let's convert the users guess from a string to a number.
  53.     users_guess_number = Val(users_guess_string)
  54.     'Let's compare his guess with the secret number.
  55.     If users_guess_number < the_secret_number Then
  56.         MsgBox (users_guess_number & " is too low")
  57.     End If
  58.     
  59.     If users_guess_number > the_secret_number Then
  60.         MsgBox (users_guess_number & " is too high")
  61.     End If
  62.     
  63.     If users_guess_number = the_secret_number Then
  64.         MsgBox (users_guess_number & " was the number! Congratulations!")
  65.         Exit Sub 'We have to exit the sub here, or we'll continue with the For-Next loop.
  66.     End If
  67.     
  68. Next counter
  69.  
  70. End Sub
  71.  
  72.  
  73.